package cn.csg.iotplatform.module.system.controller.admin.permission.vo.role;

import cn.csg.iotplatform.module.system.util.ToolUtil;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Schema(description = "角色管理 - 角色信息excel Response vo")
@Data
@ExcelIgnoreUnannotated
public class RoleExcelVo {

    @Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "管理员")
    @ExcelProperty("角色名称")
    private String name;

    @Schema(description = "角色描述", example = "我是一个角色")
    @ExcelProperty("角色描述")
    private String remark;

    @Schema(description = "数据范围，参见 DataScopeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @ExcelProperty("管理范围")
    private String dataScopeDesc;

    @Schema(description = "是否公共 0否,1是", example = "0")
    @ExcelProperty("是否公用")
    private String isPublicDesc;

    @Schema(description = "创建人", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建人")
    @ExcelProperty("创建人")
    private String creatorName;

    @Schema(description = "创建单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建单位")
    @ExcelProperty("创建单位")
    private String creatorDept;

    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
    private LocalDateTime createTime;

    @ExcelProperty("创建时间")
    private String createTimeDesc;

    public String getCreateTimeDesc() {
        if (ToolUtil.isEmpty(createTime)) {
            return "";
        }
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // 创建格式化器
        return createTime.format(formatter).equals("1970-01-01 00:00:00") ? "" : createTime.format(formatter);
    }
}
